import { fetch } from '../fetch' // 引用fetch.js

export function createTemplateAction ({title, name, serverUrl, type, backgroundImg, description, timeId1, timeId7, timeId30, timeId365}) { // 创建模板
  let ss = []
  ss[0] = {timeId: 1, price: timeId1}
  ss[1] = {timeId: 7, price: timeId7}
  ss[2] = {timeId: 30, price: timeId30}
  ss[3] = {timeId: 365, price: timeId365}
  console.log(ss)
  let data = new FormData()
  data.append('title', title)
  data.append('templateName', name)
  data.append('serveUrl', serverUrl)
  data.append('type', type)
  data.append('backgroundImg', backgroundImg)
  data.append('description', description)
  data.append('timePriceMap', ss)
  return fetch({
    url: '/littlefinger/template/createTemplate',
    method: 'post', // 请求方法
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export function getTemplateAction () { // 获取开发者模板
  return fetch({
    url: '/littlefinger/template/getTemplateList',
    method: 'get'// 请求方法
  })
}

export function updateTemplateAction (templateId, title, name, serverUrl, type, description) { // 更新开发者模板
  let data = new FormData()
  data.append('templateId', templateId)
  data.append('title', title)
  data.append('templateName', name)
  data.append('type', type)
  data.append('serveUrl', serverUrl)
  data.append('description', description)
  return fetch({
    url: '/littlefinger/template/updateTemplateText',
    method: 'post', // 请求方法
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export function replaceBackgroundAction ({templateId, backgroundImg}) { // 更新开发者模板背景图片
  let data = new FormData()
  data.append('templateId', templateId)
  data.append('backgroundImg', backgroundImg)
  return fetch({
    url: '/littlefinger/template/replaceBackground',
    method: 'post', // 请求方法
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
